package com.guanghua.brick.html;

public class CommonReplace implements IReplace {
	
	private String target = null;
	private String replacement = null;
	private boolean all = true;
	private boolean regex = true;
	

	public String replace(String data) {
		if (data != null && target != null && replacement != null) {
			if (regex) {
				if (all) {
					return data.replaceAll(target, replacement);
				} else {
					return data.replaceFirst(target, replacement);
				}
			} else {
				return data.replace(target, replacement);
			}
		} else
			return data;
	}


	public boolean isAll() {
		return all;
	}


	public void setAll(boolean all) {
		this.all = all;
	}


	public boolean isRegex() {
		return regex;
	}


	public void setRegex(boolean regex) {
		this.regex = regex;
	}


	public String getReplacement() {
		return replacement;
	}


	public void setReplacement(String replacement) {
		this.replacement = replacement;
	}


	public String getTarget() {
		return target;
	}


	public void setTarget(String target) {
		this.target = target;
	}
}
